<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@include file="../WEB-INF/jspf/controlesessao.jspf"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Lista Cursos</title>
        <script type="text/javascript" src="../js/jquery.js" ></script>
        <script type="text/javascript" src="../js/jquery.validate.js"></script>
        <script type="text/javascript" src="../js/forms.js"></script>
        <script type="text/javascript" src="../js/jquery-ui-1.8.2.custom.min.js" ></script>
        <link rel="stylesheet" href="../css/ui-lightness/jquery-ui-1.8.2.custom.css">
    <link rel="stylesheet" href="../css/forms.css"></head>
   
    <body>
        <div id="formulario">
            
            <h1>Cursos</h1>
            <form method="post">
                <p><label class="lbInput">Área</label>
                <sql:query var="query" dataSource="jdbc/dbo_MicrosoftSQLServer">
                    SELECT  *
                    FROM areas
                    order by desc_area
                </sql:query>
                <select name="id_area">
                    <option value="">Todos</option>
                    <c:forEach var="row" items="${query.rows}">
                        <option value="${row.id_area}" ${row.id_area==param.id_area?'selected':''}>${row.desc_area}</option>
                    </c:forEach>
                </select>
            </p>
            <p>

                <label class="lbInput">Nome do curso</label>
                <input name="nome_curso" value="${param.nome_curso}" type="text" size="50">
            </p>
            <p>
                <input type="submit" class="submit" value="Pesquisar">
            </p>
                
            <input type="hidden" id="token" name="token" value="${sessionScope.token}" /> </form>
            
            <br>
            <sql:query var="query" dataSource="jdbc/dbo_MicrosoftSQLServer">
                SELECT  Cursos.* ,desc_area,desc_tipocurso
                FROM Cursos
                inner join Areas on areas.id_area=cursos.id_area
                inner join TipoCursos on TipoCursos.id_tipocurso=cursos.id_tipocurso
                where nome_curso like ?
                <sql:param value="${param.nome_curso}%"/>
                <c:if test="${!empty param.id_area}">
                    and areas.id_area=?
                    <sql:param value="${param.id_area}"/>
                </c:if>
                order by nome_curso
            </sql:query>
            <table class="tablescroll" cellspacing="0" width="97%">  <thead>
                    <th>Área</th>
                    <th>Modalidade</th>
                    <th>Código</th>
                    <th>Versão</th>
                    <th>Curso</th>
                </thead>
                <tfoot>
                    <tr>
                        <td colspan="5">
                            ${query.rowCount} registros encontrados
                        </td>
                    </tr>
                </tfoot>
                <tbody>
                    <c:forEach var="row" items="${query.rows}">
                        <tr><td>${row.desc_area}</td>
                            <td>${row.desc_tipocurso}</td>
                            <td>${row.codigo_curso}
                            </td>
                            <td>${row.versao_curso}</td>
                            <td>
                                <a href="fm_update_Cursos.jsp?token=${sessionScope.token}&chave=${row.id_curso}">
                                ${row.nome_curso}                                    
                                </a>
                            </td>
                        </tr>
                     </c:forEach>
                    </tbody>

                </table>               
            </div>
        </body>
    </html>
